package com.adcok.lcdns.util;

import java.io.IOException;
import java.util.List;

import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.util.Log;

public class BKAddress {
	private String mCountry;
	private String mCity;
	private String mGuGun;
	private String mBunji;
	private String mDong;
	private String mDo;
	private String mFullAddress;
	
	
	public BKAddress(Location loc, Context context) {
		Geocoder geoCoder = new Geocoder(context);
		List<Address> addresses = null;
		
		try {
			addresses = geoCoder.getFromLocation(loc.getLatitude(), loc.getLongitude(), 5);
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		if(addresses.size() > 0){
			Address mAddress = addresses.get(0);
			//String Area = mAddress.getCountryName();
			
			mCountry = mAddress.getCountryName();
			mCity = mAddress.getLocality();
			mGuGun = mAddress.getSubLocality();
			mBunji = mAddress.getFeatureName();
			mDong = mAddress.getThoroughfare();
			mDo = mAddress.getLocality();
			mFullAddress = mAddress.getAddressLine(0);
			
			
			Log.w("BenTag", "SubAdminArea : " + mAddress.getSubAdminArea() + ", SubThroughfare : " + mAddress.getSubThoroughfare() + ", Permises : " + mAddress.getPremises()
					+ ", AdminArea : " + mAddress.getAdminArea() + ", Locality : " + mAddress.getLocality());
			
			
			Log.w("BenTag", "Addressline(0) : " + mFullAddress);
		}
	}
	
	public String getCountry() {
		return mCountry;
	}
	
	public String getCity() {
		return mCity;
	}
	
	public String getGuGun() {
		return mGuGun;
	}
	
	public String getBunji() {
		return mBunji;
	}
	
	public String getDong() {
		return mDong;
	}
	
	public String getDo() {
		return mDo;
	}
	
	public String getFullAddress() {
		String result = "";
		if(mDo.equals(mCity)) {
			result = mCity + " " + mGuGun + " " + mDong + " " + mBunji;
			Log.d("BenTag", "서울 또는 광역시");
		} else {
			result = mDo + " " + mCity + " " + mGuGun + " " + mDong + " " + mBunji;
		}
		return result;
	}
}
